package com.spa.domain.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.application.command.admin.MassagistWithdrawPayCommand;
import com.spa.domain.entity.MassagistWithdrawRecord;
import com.spa.infrastructure.enums.withdraw.WithdrawStatusEnum;
import com.spa.infrastructure.mapper.MassagistWithdrawRecordMapperStruct;
import com.spa.infrastructure.repository.condition.MassagistWithdrawRecordCondition;
import com.spa.infrastructure.repository.po.MassagistWithdrawRecordPO;
import com.spa.infrastructure.repository.service.MassagistWithdrawRecordRepositoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class MassagistWithdrawRecordService {

    @Autowired
    private MassagistWithdrawRecordRepositoryService massagistWithdrawRecordRepositoryService;

    public void add(MassagistWithdrawRecordPO po) {
        po.setStatus(WithdrawStatusEnum.$10.getCode());
        po.setApplyTime(new Date());
        massagistWithdrawRecordRepositoryService.add(po);
    }

    public Page<MassagistWithdrawRecord> page(MassagistWithdrawRecordCondition condition) {
        return MassagistWithdrawRecordMapperStruct.INSTANCE.po2Entity4Page(massagistWithdrawRecordRepositoryService.page(condition));
    }

    public List<MassagistWithdrawRecord> list(MassagistWithdrawRecordCondition condition) {
        return MassagistWithdrawRecordMapperStruct.INSTANCE.po2Entity4List(massagistWithdrawRecordRepositoryService.list(condition));
    }

    public MassagistWithdrawRecord getDetailById(long id) {
        return MassagistWithdrawRecordMapperStruct.INSTANCE.po2Entity(massagistWithdrawRecordRepositoryService.getMassagistWithdrawRecordPOById(id));
    }

    public void shopAudit(long id, long auditId, String auditName) {
        MassagistWithdrawRecordPO po = new MassagistWithdrawRecordPO();
        po.setId(id);
        po.setAuditTime(new Date());
        po.setAuditId(auditId);
        po.setAuditName(auditName);
        po.setStatus(WithdrawStatusEnum.$20.getCode());
        massagistWithdrawRecordRepositoryService.updateMassagistWithdrawRecord(po);
    }

    public void payForMassagist(MassagistWithdrawPayCommand command) {
        MassagistWithdrawRecordPO po = new MassagistWithdrawRecordPO();
        po.setId(command.getWithdrawId());
        po.setCredentials(command.getCredentials());
        po.setStatus(WithdrawStatusEnum.$30.getCode());
        po.setPayTime(new Date());
        massagistWithdrawRecordRepositoryService.updateMassagistWithdrawRecord(po);
    }
}
